const express = require('express');
const seq = require('../config/database').seq;
const adminCtrl = require('../controller/admin');
const router = express.Router();
//const adminModel = require('../models/adminModel');

const isLoginMid = function(req, res, next) {
	if (req.session.username == undefined) {
		res.redirect('adminlogin');
	} else {
		next();
	}
}

//显示管理员列表
router.get('/', function(req, res, next) {
	global.navlist = 6;
	res.render('admin');
});

router.get('/login', function(req, res, next) {
	res.render('adminlogin');
});
router.post('/login', function(req, res, next) {
	console.log(req.body.username);
});

//添加管理员
router.post('/create', function(req, res, next) {
	/*let now = Date.now();
	adminModel.create({
		username: 'admin',
		nickname: 'admin',
		password: '123456',
		email: '1234567',
		loginip: req.ip,
		logintime: now,
		token: '1234567890',
		status: '2'
	}).then(data => {
		res.send(data);
	}).catch(err => {
		res.json(err.fields.username);
	})*/
})

//修改管理员
router.post('/update', function(req, res, next) {
	adminModel.update({}, {
		where: { id: { eq: 23 } }
	}).then(data => {
		res.json(data);
	});
})

//删除管理员
router.post('/delete', function(req, res, next) {
	//console.log(db);
	adminModel.destroy({
		where: { id: { eq: 23 } }
	}).then(data => {
		res.json(data);
	})
})

module.exports = router;